import * as YvanUI from 'yvan-ui-wotu'
import {stringify} from "qs";

export interface Ref {

}

export interface Inp {
    inId: string
}


// function watch<T, R>(watchFunc: () => T, thenFunc: (arg: T) => R): Watcher<T, R> {
//     return new Watcher<T, R>(watchFunc, thenFunc)
// }
//
// type Dict = Array<{ id: string, value: string }>
//
// type PromiseNullableResult<T> = YvanUI.PromiseMabe<T> | null | undefined
//
//
// type DictStruct = Array<{ id: string, value: string }>
//
// type Transform<F, T> = (from: F) => T
//
// function Dict(data: any): DictStruct {
//     return []
// }
//
// export function dataSource<T>(convert: Transform<any, T>, option: DataSourceOption<any, T>): DataSourceWatcher<any, T> {
//     return new DataSourceWatcher<any, T>(option)
// }

export default class DemoScopeData extends YvanUI.Scope<Inp, Ref> {

    main = this.$$({
        form1: {
            f1: 'a1',
            f2: 'a2',
            f3: 'a3',
        },

        form2: {
            f1: 'b1',
            f2: 'b2'
        }
    })

    watchMethod() {
        const watcher = this.watch(
            () => parseInt(this.main.form1.f1) + parseInt(this.main.form2.f2),
            (v) => ({
                a: 1,
                b: 2
            }));
        // dataSource(Dict, {
        //     url: '',
        //     method: 'post-json',
        //
        // }).get(r => {
        //
        // });
    }


    vjson = this.$$({
        title: '数据源示例',
        items: [
            {
                view: 'form',
                debug: 'data',
                visible: this.$watch(() => this.main.form2.f1 !== null),
            },
            {
                view: 'grid',
                columns: [
                    {
                        field: 'a',
                        label: 'aa',
                        formatter: this.$request({
                            url: '',
                            method: ''
                        })
                    }
                ]
            }
        ]
    })

    onRender() {
        window['biz'] = this
    }
}
